#!/alidata/server/php/bin/php
<?php
error_reporting(0);
ini_set('memory_limit', '1000M');
set_time_limit(0);


/** 
 *  mapper8.php
 *      input:��ʽ��(unique_id\tmin_price\tcnt\tdeviation\tjson1\tjson1...)
 *      handle:���sql(house_sell_pic)
				��ͼƬ�ϴ���������
 *      output:sql���--INSERT INTO `house_sell_pic` VALUES ('1', ...);`
 * @created 2016-05-03
 * @by lily
 */
$nu=0;
CONST nuull=null;
CONST pic_type1=1;
CONST pic_type2=2;
while (($line_json = fgets(STDIN)) !== false) {   //line_json=>source_url\tjson��ʽ
    
    $line_json = trim($line_json);
    if (empty($line_json))
        continue;
	$aa=explode("\t", $line_json);
    //list ($unique_id,$min_price, $cnt, $deviation, $list_json) = explode("\t", $line_json);
	for($i=5;$i<count($aa);$i++){  
		$one_dejson=json_decode($aa[$i],true); 
		//���?��ͼ--house_pic_layout
		$urls=explode("|", $one_dejson['house_pic_layout']);
		for ($ii=0;$ii<count($urls);$ii++){
			if(!empty($urls[$ii])){
				if($nu==0){
					echo "INSERT INTO house_sell_pic(pic_rule,pic_thumb,pic_desc,house_sell_id,creater,city_id,pic_type,pic_source_url,time,gov_id) VALUES";
					$nu=1;}  
				else{
					echo ",\n";
					$nu+=1;
				}
#			$pic_id=$one_dejson['city_id']."_".$one_dejson['source']."_".$one_dejson['id']."_".pic_type2."_".$ii;
# $ypy_path = '/sell/layout/'.$pic_id.'.jpg';	
                        $ypy_path = '/sell/layout/xian_'.$value['source'].'_'.$one_dejson['id'].'_1_'.$k.'_'.uniqid('',true).mt_rand(10000, 99999).'.jpg';
			#$pic_path = 'http://zhaijiso-pic.b0.upaiyun.com'.$ypy_path;
            $pic_path = $ypy_path;
			echo " ('".$pic_path."','".nuull."','".nuull."','".$aa[0]."','".nuull."','".
						$one_dejson['city_id']."','".pic_type2."','".$urls[$ii]."','".
						date('Y-m-d h:i:s',time())."','".$one_dejson['id']."')";
					
		}
		
		
			if($nu==1){
				echo ";\n";
				$nu=0;
			}
		}
		//���?Դͼ--house_pic_unit
		$urls2=explode("|", $one_dejson['house_pic_unit']);
        $urls2=array_unique($urls2);
		for ($ii=0;$ii<count($urls2);$ii++){
			if(!empty($urls2[$ii])){
				if($nu==0){
				echo "INSERT INTO house_sell_pic(pic_rule,pic_thumb,pic_desc,house_sell_id,creater,city_id,pic_type,pic_source_url,time,gov_id) VALUES";
				$nu=1;}  
				else{
					echo ",\n";
					$nu+=1;
				}
#$pic_id=$city."_".$one_dejson['source']."_".$one_dejson['id']."_".pic_type1."_".$ii;
#                   $ypy_path = '/sell/unit/'.$pic_id.'.jpg';
                 $ypy_path = '/sell/unit/xian_'.$value['source'].'_'.$one_dejson['id'].'_1_'.$k.'_'.uniqid(''    ,true).mt_rand(10000, 99999).'.jpg';

            $pic_path = $ypy_path;
			echo " ('".$pic_path."','".nuull."','".nuull."','".$aa[0]."','".nuull."','".
						nuull."','".pic_type1."','".$urls2[$ii]."','".
						date('Y-m-d h:i:s',time())."','".$one_dejson['id']."')";
				}
			if($nu==1){
				echo ";\n";
				$nu=0;
			}
		}
		
		
	}
}
echo ";\n";
	
?>
